<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/commons/meta.jsp"%>
<script type="text/javascript">
	$(function(){
		var menuOrder = '${menuOrder}';
		if(menuOrder == ''){
			menuOrder = 0;
		}
		$(".nav1").find("li").removeClass("li_hover");
		$(".nav1").find("li").eq(menuOrder).addClass("li_hover");
	});
</script>
	<div class="content">
		<div class="head">
			<div class="f_l">
				<img src="${ctx }/static/images/frame/logo.png" alt="" style="width: 48px;" /><span class="company-name">计量检测业务管理系统</span>
			</div>
			<div class="f_r">
				<img src="${ctx }/static/images/frame/icon_acc.png" alt="" />
				<span>你好!${LoginUser.userName }（${LoginUser.deptName }）</span>
				<a href="javascript:void(0)" onclick="changePwd()">修改密码&nbsp;|</a>
				<a href="javascript:void(0)" onclick="logout()">退出系统&nbsp; </a>
			</div>
		</div>
		<div class="nav">
			<ul>
				<c:forEach items="${menuList}" var="v" varStatus="i" >
					<c:if test="${v.menu_lvl eq 1}">
						<li>
							<p  menuId="${v.menu_id}" id="frame_menu_${i.count }">${v.menu_name } </p>
						</li>
					</c:if>
				</c:forEach>
			</ul>
		</div>
	</div>
<script>
	var headers = {};
	headers['__RequestVerificationToken'] = "${RequestVerificationToken}";
	$(document).ready(function(){
		$(".nav ul li p").click(function(){
			var $this = $(this);
			if(!$this.hasClass("current")){
				$(".nav ul li p").removeClass();
				$this.addClass('current');
				var menuId = $(this).attr('menuId');
				var fid = $(this).attr('id');
				loadSubMenu(menuId,fid);
			}
		});
		$('#frame_menu_1').click();
	});
	function logout(){
		confirmMsg("确定要退出？",function(){
			window.location = "${ctx}/login/logouts";
		});
	}
	function loadSubMenu(menuId,fid){
		var menuStr = $('#sub_'+fid).html();
		if(!isEmpty(menuStr)){
			$('#westMenuDiv').html(menuStr);
			initSubMenu();
		}else{
			executeAjax('${ctx}/frameIndex/getSubMenuDiv','menuId='+menuId,function(data){
				$('#westMenuDiv').html(data);
				$('#sub_'+fid).remove();
				$(document.body).append('<div id="sub_'+fid+'">'+data+'</div>'); 
				initSubMenu();
			});
		}
	}
	function initSubMenu(){
		$(".main .f_l .nav2 ul li").click(function(){
			var $this = $(this);
			$(".main .f_l .nav2 ul li").removeClass();
			$this.addClass('current1');
			var menuId = $this.attr("menuId");
			var url = $this.attr("url");
			var title = $this.attr("title");
			url = '${ctx}'+url;
			if(url.indexOf("?") == -1){
				url += "?";
			}else{
				url += "&";
			}
			addTab(title,url+"menuId="+menuId,menuId);
		});
		$(".nav1").click(function(){
			if($(this).children(".nav2").css('display') == 'none'){
				$(".nav2").slideUp()
				$(this).children(".nav2").slideToggle();
			}
		});
		$(".nav1:first").click();
	}
	function changePwd(){
			openWindow("修改密码",width1,210,"${ctx}/frameIndex/updatePassword",[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
					resetPw();
				}
			},{
				text:'取消',
				iconCls:'icon-no',
				handler:function(){
					closeWindow();
				}
			}]);
		}
		
		function resetPw(){
		    var pp = parent;
		    var editFrame = pp.winFrame;
			var old_password = editFrame.window.oldpassword();
			var newPassword = editFrame.window.newPassword();
			var newPassword2 = editFrame.window.newPassword2();
			
			if(trim(old_password).length==0){
				alertMsg("请输入原始密码！","warning",function(){
					try{
					 	$('#oldPassword').focus();
				 	 }catch(e){}
				});	
				return;
			}
			if(trim(newPassword).length==0){
				alertMsg("请输入新密码！","warning",function(){
					try{
					 	$('#oldPassword').focus();
				 	 }catch(e){}
				});
				return;
			}
			
			if(trim(newPassword) != trim(newPassword2)){
				alertMsg("两次密码输入的不一致！","warning",function(){
					try{
					 	$('#newPassword2').focus();
				 	 }catch(e){}
				});
				return;
			}
			confirmMsg("确定要保存吗？",function(){
				$.ajax({
					cache: false,
					type: "POST",
					headers: headers,
					url:"${ctx}/frameIndex/updatePw",
					data:{oldPassword:old_password,newPassword:newPassword},
					async: false,
				    error: function(request) {
				    	$.messager.alert('操作提示',"操作失败！","error");
				    },
				    success: function(data) {
				    	if(data && "success" == data){
				    		$.messager.alert('操作提示',"修改成功！","info",function(){
						         closeWindow();
				         	});
			         	}else if("1" == data){
			         		$.messager.alert('操作提示',"原始密码不正确，请重新输入！","warning");
			         	}else{
			         		$.messager.alert('操作提示',"操作失败！","error");
			         	}
				    }
				});
			});
		}
</script>
